<template>
  <div class="login">
    <div class="login-form">
      <div class="login-form-header">
        <div class="logo-and-text">
          <img style="width: 75px; height: 75px;float: left;padding-right: 40px;" src="../assets/img/logo.png"
               alt=""/>
          <div class="login-logo-text">梦星河影院</div>
        </div>
        <div class="login-form-text">登录</div>
      </div>
      <div style="color: #91949c;font-weight: bolder">
        <p>账号</p>
        <el-input class="login-form-input" v-model="username" placeholder="账 号"></el-input>
        <p>密码</p>
        <el-input class="login-form-input" placeholder="密 码" v-model="password" show-password></el-input>
        <div style="padding-top: 10px">
          <el-checkbox v-model="remember">记住密码</el-checkbox>
          <div style="float: right">
            <el-link href="/forget" style="font-weight: bolder;font-size: 14px;color: #91949c;"
                     :underline="false">
              忘记密码?
            </el-link>
          </div>
        </div>
        <el-row>
          <el-button @click="postLogin" class="login-form-button" type="primary">登录</el-button>
          <el-button @click="postLoginNoUser" class="login-form-button-guest" type="info">访客登录</el-button>
        </el-row>
      </div>
      <div class="login-form-footer">
        <el-link href="/register" style="font-weight: bolder;font-size: 16px;color: #91949c;"
                 :underline="false">
          还没有账号？去注册
          <i style="font-weight: bolder;font-size: 15px" class="el-icon-right"></i>
        </el-link>
      </div>
    </div>
  </div>
</template>

<script>

import {Login} from "../api/user"

export default {
  data() {
    return {
      username: '',
      password: '',
      remember: false,
    }
  },
  mounted() {
  },
  methods: {
    postLogin() {
      const LoginData = {
        username: this.username,
        password: this.password,
        remember: this.remember
      };
      console.log(LoginData);
      Login(LoginData).then(res => {
        this.$message({
          message: '登录成功!',
          type: 'success'
        });
        localStorage.setItem("uid", res.data.user.id);
        localStorage.setItem("token", res.data.token);
        console.log("I'm in login!")
        console.log("uid: " + localStorage.getItem("uid"))
        console.log("token: " + localStorage.getItem("token"))

        this.$router.push({path: '/', replace: true});
        //更新状态
        let aboutRoute = this.$route.fullPath
        if (aboutRoute == '/') {
          window.location.reload(true);
        }
      });
    },
    postLoginNoUser() {
      const LoginData = {
        username: "nouser",
        password: "123456",
        remember: false
      };
      console.log(LoginData);
      Login(LoginData).then(res => {
        localStorage.setItem("uid", res.data.user.id);
        localStorage.setItem("token", res.data.token);
        this.$router.push({path: '/', replace: true});

      });
    }
  }
}
</script>

<style scoped>

.login {
  width: 100%;
  height: 100%;
  background: #FFFFFF;
  font-family: "PingFang SC", "Microsoft YaHei", Arial, Helvetica, sans-serif, "宋体";
}

.login-form {
  width: 500px;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -60%);
  letter-spacing: 2px;
}

.login-form-header {
  color: #f0f0f0;
  height: 20px;
  padding-left: 45px;
  padding-bottom: 100px;
}

.login-logo-text {
  font-family: "抖音美好体", "Microsoft YaHei", Arial, Helvetica, sans-serif, "宋体";
  font-size: 50px;
  line-height: 75px;
}

.login-form-text {
  position: absolute;
  left: 0px;
  width: 500px;
  text-align: center;
  color: #f0f0f0;
  font-weight: bold;
  font-size: 30px;
  padding-top: 10px;
}

.login-form-input {
  margin-bottom: 10px;
}

.login-form-button {
  border-radius: 3px;
  width: 200px;
  font-weight: 600;
  font-size: 15px;
  letter-spacing: 2px;
  height: 60px;
  box-shadow: rgb(38, 57, 77) 0px 20px 30px -10px;
  margin-top: 35px;
  margin-left: 30px;
  float: left;
  background-color: #7b8cf6;
  transition: all 0.3s ease-in-out;
}

.login-form-button:hover {
  background-color: #909df4;
  transition: all 0.3s ease-in-out;
}

.login-form-button-guest {
  border-radius: 3px;
  width: 200px;
  font-weight: 600;
  font-size: 15px;
  letter-spacing: 2px;
  height: 60px;
  box-shadow: rgb(38, 57, 77) 0px 20px 30px -10px;
  margin-top: 35px;
  float: left;
  margin-left: 30px;
  transition: all 0.3s ease-in-out;
}

.login-form-footer {
  font-weight: bolder;
  color: #91949c;
  padding-top: 40px;
  text-align: center;
}

>>> .el-input__inner {
  height: 48px;
}

::v-deep .el-input__inner {
  background-color: #494560;
  border: none;
  color: #f0f0f0;
  font-family: "PingFang SC", "Microsoft YaHei", Arial, Helvetica, sans-serif, "宋体";
}

.el-checkbox {
  color: #91949c;
  font-weight: bolder;
  font-size: 15px;
}

::v-deep .el-checkbox__input.is-checked .el-checkbox__inner, .el-checkbox__input.is-indeterminate .el-checkbox__inner {
  background-color: #7b8cf6;
  border-color: #7b8cf6;;
}

::v-deep .el-checkbox__input.is-checked + .el-checkbox__label {
  color: #7b8cf6;
}
</style>
